package com.spic.business.plan.analysis.service.impl;

import com.spic.business.plan.analysis.dto.PlanAnalysisDTO;
import com.spic.business.plan.analysis.dto.PlanUserDTO;
import com.spic.business.plan.analysis.mapper.PlanUserPostTeamGroupMapper;
import com.spic.business.plan.analysis.service.IPlanAnalysisService;
import com.spic.business.plan.analysis.vo.CategoryChartVo;
import com.spic.business.plan.analysis.vo.PlanAnalysisVo;
import com.spic.business.plan.analysis.vo.PlanEmergencyResponseVo;
import com.spic.business.plan.drill.domain.PlanDrillPlan;
import com.spic.business.plan.drill.domain.PlanDrillPlanDetail;
import com.spic.business.plan.drill.service.IPlanDrillPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * @author 290512
 * @create 2021-10-29 18:22
 */
@Service
public class PlanAnalysisServiceImpl implements IPlanAnalysisService
{
    @Autowired
    private PlanUserPostTeamGroupMapper  planUserPostTeamGroupMapper;

    @Autowired
    private IPlanDrillPlanService planDrillPlanService;
    /**
     * 返回数据中心统计接口
     *
     * @param planAnalysisDTO
     * @return
     */
    @Override
    public HashMap<String,Object> selectPlanList(PlanAnalysisDTO planAnalysisDTO)
    {
        HashMap<String ,Object> examResultDTOListMap = new HashMap<>();
        //本月计划总数（环比）、已执行数（环比）、按期执行率（环比）、应急启动数量（环比）、超期未演练
        /**
         * 返回对象
         */
        PlanEmergencyResponseVo monthTop = new PlanEmergencyResponseVo();
        monthTop.setTotalNumberPlan(5);
        monthTop.setTotalNumberPlanSequential(33.33d);
        monthTop.setHasNumberExecutions(2);
        monthTop.setHasNumberExecutionsSequential(44.34d);
        monthTop.setSchedulExecutionRate(100.22d);
        monthTop.setSchedulExecutionRateSequential(121.88d);
        monthTop.setStartNumber(5);
        monthTop.setStartNumberSequential(79.33d);
        monthTop.setOverdueNoDrill(1);
        examResultDTOListMap.put("monthTop", monthTop);


        //本年计划总数（环比）、已执行数（环比）、按期执行率（环比）、应急启动数量（环比）、超期未演练
        PlanEmergencyResponseVo yearsTop = new PlanEmergencyResponseVo();
        yearsTop.setTotalNumberPlan(7);
        yearsTop.setTotalNumberPlanSequential(33.33d);
        yearsTop.setHasNumberExecutions(1);
        yearsTop.setHasNumberExecutionsSequential(44.34d);
        yearsTop.setSchedulExecutionRate(100.22d);
        yearsTop.setSchedulExecutionRateSequential(121.88d);
        yearsTop.setStartNumber(2);
        yearsTop.setStartNumberSequential(79.33d);
        yearsTop.setOverdueNoDrill(0);
        examResultDTOListMap.put("yearsTop", yearsTop);
        //执行偏差率
        Double executiveDeviation = 7.33d;
        examResultDTOListMap.put("executiveDeviation",executiveDeviation);

        //计划演练数量分级统计 公司/厂矿级 %  部门/车间级 %  和数量
        int plantoDrill [] =new int[2];
        // TODO
        plantoDrill[0] = 2;
        plantoDrill[1] = 3;
        examResultDTOListMap.put("plantoDrill",plantoDrill);

        //应急预案分类统计
        int classificationEmergencyPlans [] =new int[3];
        // TODO
        classificationEmergencyPlans[0] = 3;
        classificationEmergencyPlans[1] = 4;
        classificationEmergencyPlans[2] = 2;
        examResultDTOListMap.put("classificationEmergencyPlans",classificationEmergencyPlans);

        //折线图统计
        //执行偏差值
        int emergencyCategoryChart [] =new int[3];
        emergencyCategoryChart[0] = 3;
        emergencyCategoryChart[1] = 2;
        emergencyCategoryChart[2] = 4;
        CategoryChartVo categoryChartVoone = new CategoryChartVo();
        categoryChartVoone.setCategorValue(emergencyCategoryChart);
        categoryChartVoone.setCategorYears();
        examResultDTOListMap.put("emergencyCategoryChart",categoryChartVoone);

        //按期执行率
        int scheduleExecutionRateChart [] =new int[3];
        scheduleExecutionRateChart[0] = 1;
        scheduleExecutionRateChart[1] = 3;
        scheduleExecutionRateChart[2] = 1;
        CategoryChartVo categoryChartVotwo = new CategoryChartVo();
        categoryChartVotwo.setCategorValue(scheduleExecutionRateChart);
        categoryChartVotwo.setCategorYears();
        examResultDTOListMap.put("scheduleExecutionRateChart",categoryChartVotwo);

        //超期未演练数量
        int numberOverdueDrillsChart [] =new int[3];
        numberOverdueDrillsChart[0] = 2;
        numberOverdueDrillsChart[1] = 1;
        numberOverdueDrillsChart[2] = 3;
        CategoryChartVo categoryChartVothr = new CategoryChartVo();
        categoryChartVothr.setCategorValue(numberOverdueDrillsChart);
        categoryChartVothr.setCategorYears();
        examResultDTOListMap.put("numberOverdueDrillsChart",categoryChartVothr);

        //预案启动数量
        int numberOfPlanChart [] =new int[3];
        numberOfPlanChart[0] = 4;
        numberOfPlanChart[1] = 2;
        numberOfPlanChart[2] = 3;
        CategoryChartVo categoryChartVoforu = new CategoryChartVo();
        categoryChartVoforu.setCategorValue(numberOfPlanChart);
        categoryChartVoforu.setCategorYears();
        examResultDTOListMap.put("numberOfPlanChart",categoryChartVoforu);
        return examResultDTOListMap;
    }

    /**
     * 组织接口
     * @return
     */
    public List<PlanUserDTO> selectPlanUserList(){
        return planUserPostTeamGroupMapper.selectPlanUserDTO();
    }
    /**
     * 超期未演练
     * @param planAnalysisVo
     * @return
     */
    @Override
    public List<PlanAnalysisVo> selectemergencyplantableList(PlanAnalysisVo planAnalysisVo)
    {
        List<PlanAnalysisVo> planAnalysisVoList = new ArrayList<>();
        PlanDrillPlan drill = new PlanDrillPlan();
        List<PlanDrillPlan> planDrillPlanList = planDrillPlanService.selectPlanDrillPlanList(drill);
        for (PlanDrillPlan planDrillPlan : planDrillPlanList)
        {

            String category = planDrillPlan.getCategory(); //类型
            String level = planDrillPlan.getLevel(); //级别
            String name = planDrillPlan.getName();//名称
            PlanDrillPlan planDrillPlan1 = planDrillPlanService.selectPlanDrillPlanById(planDrillPlan.getId());
            List<PlanDrillPlanDetail> planDrillPlanDetailList = planDrillPlan1.getPlanDrillPlanDetailList();
            for (PlanDrillPlanDetail planDrillPlanDetail : planDrillPlanDetailList)
            {
                PlanAnalysisVo planAnal = new PlanAnalysisVo();
                Date beginTime = planDrillPlanDetail.getBeginTime();
                Date endTime = planDrillPlanDetail.getEndTime();
                String joinDepartment = planDrillPlanDetail.getJoinDepartment(); //参加部门单位
                String organizeDepartment = planDrillPlanDetail.getOrganizeDepartment(); //组织部门
                planAnal.setBeginTime(beginTime);
                planAnal.setEndTime(endTime);
                planAnal.setName(name);
                planAnal.setCategory(category);
                planAnal.setLevel(level);
                planAnal.setJoinDepartment(joinDepartment);
                planAnal.setOrganizeDepartment(organizeDepartment);
                planAnalysisVoList.add(planAnal);
            }

        }
        return planAnalysisVoList;
    }
    /**
     * 待演练
     * @param planAnalysisVo
     * @return
     */
    @Override
    public List<PlanAnalysisVo> selecttodrilltableList(PlanAnalysisVo planAnalysisVo)
    {
        List<PlanAnalysisVo> planAnalysisVoList = new ArrayList<>();
        PlanDrillPlan drill = new PlanDrillPlan();
        List<PlanDrillPlan> planDrillPlanList = planDrillPlanService.selectPlanDrillPlanList(drill);
        for (PlanDrillPlan planDrillPlan : planDrillPlanList)
        {

            String category = planDrillPlan.getCategory(); //类型
            String level = planDrillPlan.getLevel(); //级别
            String name = planDrillPlan.getName();//名称
            PlanDrillPlan planDrillPlan1 = planDrillPlanService.selectPlanDrillPlanById(planDrillPlan.getId());
            List<PlanDrillPlanDetail> planDrillPlanDetailList = planDrillPlan1.getPlanDrillPlanDetailList();
            for (PlanDrillPlanDetail planDrillPlanDetail : planDrillPlanDetailList)
            {
                PlanAnalysisVo planAnal = new PlanAnalysisVo();
                Date beginTime = planDrillPlanDetail.getBeginTime();
                Date endTime = planDrillPlanDetail.getEndTime();
                String joinDepartment = planDrillPlanDetail.getJoinDepartment(); //参加部门单位
                String organizeDepartment = planDrillPlanDetail.getOrganizeDepartment(); //组织部门
                planAnal.setBeginTime(beginTime);
                planAnal.setEndTime(endTime);
                planAnal.setName(name);
                planAnal.setCategory(category);
                planAnal.setLevel(level);
                planAnal.setJoinDepartment(joinDepartment);
                planAnal.setOrganizeDepartment(organizeDepartment);
                planAnalysisVoList.add(planAnal);
            }

        }
        return planAnalysisVoList;
    }
    /**
     * 预案启动
     * @param planAnalysisVo
     * @return
     */
    @Override
    public List<PlanAnalysisVo> selectplantostarttableList(PlanAnalysisVo planAnalysisVo)
    {
        List<PlanAnalysisVo> planAnalysisVoList = new ArrayList<>();
        PlanDrillPlan drill = new PlanDrillPlan();
        List<PlanDrillPlan> planDrillPlanList = planDrillPlanService.selectPlanDrillPlanList(drill);
        for (PlanDrillPlan planDrillPlan : planDrillPlanList)
        {

            String category = planDrillPlan.getCategory(); //类型
            String level = planDrillPlan.getLevel(); //级别
            String name = planDrillPlan.getName();//名称
            PlanDrillPlan planDrillPlan1 = planDrillPlanService.selectPlanDrillPlanById(planDrillPlan.getId());
            List<PlanDrillPlanDetail> planDrillPlanDetailList = planDrillPlan1.getPlanDrillPlanDetailList();
            for (PlanDrillPlanDetail planDrillPlanDetail : planDrillPlanDetailList)
            {
                PlanAnalysisVo planAnal = new PlanAnalysisVo();
                Date beginTime = planDrillPlanDetail.getBeginTime();
                Date endTime = planDrillPlanDetail.getEndTime();
                String joinDepartment = planDrillPlanDetail.getJoinDepartment(); //参加部门单位
                String organizeDepartment = planDrillPlanDetail.getOrganizeDepartment(); //组织部门
                planAnal.setBeginTime(beginTime);
                planAnal.setEndTime(endTime);
                planAnal.setName(name);
                planAnal.setCategory(category);
                planAnal.setLevel(level);
                planAnal.setJoinDepartment(joinDepartment);
                planAnal.setOrganizeDepartment(organizeDepartment);
                planAnalysisVoList.add(planAnal);
            }

        }
        return planAnalysisVoList;
    }
    /**
     * 应急预案
     * @param planAnalysisVo
     * @return
     */
    @Override
    public List<PlanAnalysisVo> selectcontingencyplantableList(PlanAnalysisVo planAnalysisVo)
    {
        List<PlanAnalysisVo> planAnalysisVoList = new ArrayList<>();
        PlanDrillPlan drill = new PlanDrillPlan();
        List<PlanDrillPlan> planDrillPlanList = planDrillPlanService.selectPlanDrillPlanList(drill);
        for (PlanDrillPlan planDrillPlan : planDrillPlanList)
        {

            String category = planDrillPlan.getCategory(); //类型
            String level = planDrillPlan.getLevel(); //级别
            String name = planDrillPlan.getName();//名称
            PlanDrillPlan planDrillPlan1 = planDrillPlanService.selectPlanDrillPlanById(planDrillPlan.getId());
            List<PlanDrillPlanDetail> planDrillPlanDetailList = planDrillPlan1.getPlanDrillPlanDetailList();
            for (PlanDrillPlanDetail planDrillPlanDetail : planDrillPlanDetailList)
            {
                PlanAnalysisVo planAnal = new PlanAnalysisVo();
                Date beginTime = planDrillPlanDetail.getBeginTime();
                Date endTime = planDrillPlanDetail.getEndTime();
                String joinDepartment = planDrillPlanDetail.getJoinDepartment(); //参加部门单位
                String organizeDepartment = planDrillPlanDetail.getOrganizeDepartment(); //组织部门
                planAnal.setBeginTime(beginTime);
                planAnal.setEndTime(endTime);
                planAnal.setName(name);
                planAnal.setCategory(category);
                planAnal.setLevel(level);
                planAnal.setJoinDepartment(joinDepartment);
                planAnal.setOrganizeDepartment(organizeDepartment);
                planAnalysisVoList.add(planAnal);
            }

        }
        return planAnalysisVoList;
    }
}
